﻿using DualReferralClient.Entity;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using UpLoadDataOnTime.DataBaseUtil;

namespace DualReferralClient.Model
{
    class DualReferralModel
    {
        IDatabase db = DbFactory.CreateDb();

        private static string connStr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;

        public YSCode getLoginInfo(string code,string passWord)
        {
            string sql = " SELECT CODE,NAME,KSCODE,KSNAME                " +
                         " FROM dbo.YSCODE(NOLOCK)                       " + 
                         " WHERE CODE = @code AND PASSWORD = @passWord   ";
            SqlParameter[] parameters = new SqlParameter[]
           {
                new SqlParameter("@code",code),
                new SqlParameter("@passWord",passWord)
           };
            YSCode YSCode = db.Context.QuerySingle<YSCode>(connStr, sql, parameters);
            return YSCode;
        }

        public List<PatientList> getPatientList(string param)
        {
            string sql = "SELECT M01 AS ZYNum,    " +
                         "       M04 AS hzxm,     " +
                         "       M05 AS sex,      " +
                         "       M03 AS jzkh,     " +
                         "       '2' AS jzklx,    " +
                         "       M08 AS sfzh,     " +
                         "       CONVERT(VARCHAR(10),M06,121) AS csrq,    " +
                         "       M09 AS lxdh,     " +
                         "       M10 AS jtdz,     " +
                         "       M40 AS cbzd,     " +
                         "       NULL AS bszy,    " +
                         "       NULL AS zyjws,   " +
                         "       NULL AS zlqk,    " +
                         "       NULL AS zzmd,    " +
                         "       'zy' AS mzzycxbz " +
                         "FROM dbo.MBASE(NOLOCK)  " +
                         "WHERE M19 IS NULL       " +
                         "AND M01 LIKE @param OR M04 LIKE @param OR M08 LIKE @param " +
                         "ORDER BY ZYNum ";
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@param",param)
            };
            List<PatientList> list = db.Context.QueryMany<PatientList>(connStr, sql, parameters);
            return list;
        }

        public List<PatientList> getPatientList()
        {
            string sql = "SELECT M01 AS ZYNum,    " +
                         "       M04 AS hzxm,     " +
                         "       M05 AS sex,      " +
                         "       M03 AS jzkh,     " +
                         "       '2' AS jzklx,    " +
                         "       M08 AS sfzh,     " +
                         "       CONVERT(VARCHAR(10),M06,121) AS csrq,    " +
                         "       M09 AS lxdh,     " +
                         "       M10 AS jtdz,     " +
                         "       M40 AS cbzd,     " +
                         "       NULL AS bszy,    " +
                         "       NULL AS zyjws,   " +
                         "       NULL AS zlqk,    " +
                         "       NULL AS zzmd,    " +
                         "       'zy' AS mzzycxbz " +
                         "FROM dbo.MBASE(NOLOCK)  " +
                         "WHERE M19 IS NULL       " +
                         "ORDER BY ZYNum ";
            SqlParameter[] parameters = new SqlParameter[]
            {
            };
            List<PatientList> list = db.Context.QueryMany<PatientList>(connStr, sql, parameters);
            return list;
        }

    }
}
